// var allmap = echarts.init(document.getElementById('allmap'));
       $(function(){
       		//弹框
	   		setInterval(function(){
	   			var tbHeight = $(".tk table").height();
	   			$(".tk").height(tbHeight);
	   			console.log($(".tk").height());
	   		},100);
	   		$(".tk_close").click(function(){
	   			console.log("11");
	   			$(".tk").hide();
	   			$(".modal").hide();
	   		});
       })
   		
   		
   		
   		//时间
            $(function(){
            setInterval(function() {

            var now_time = new Date();
                    var year = now_time.getFullYear();
                    var month = now_time.getMonth() + 1;
                    var dates = now_time.getDate();
                    var hours = now_time.getHours();
                    var minu = now_time.getMinutes();
                    var seco = now_time.getSeconds();
                    var today = now_time.getDay();
                    if (hours < 10){
            hours = '0' + hours;
            }
            if (minu < 10){
            minu = '0' + minu;
            }
            if (seco < 10){
            seco = '0' + seco;
            }
            if (today == 1){
            today = '星期一';
            } else if (today == 2){
            today = '星期二';
            } else if (today == 3){
            today = '星期三';
            } else if (today == 4){
            today = '星期四';
            } else if (today == 5){
            today = '星期五';
            } else if (today == 6){
            today = '星期六';
            } else if (today == 0){
            today = '星期日';
            }
            $('#hours').html(hours + ':' + minu + ':' + seco);
            $('#year').html(year + '年' + month + '月' + dates + '日');
            $('#today').html(today);
            }, 1000);
			})
   
   	$("#back").click(function(){
    		myChart.clear();
    		load_map_data('湖北省');
    	})

    // 全省地图数据
		var hubei_data = [
							{city:'湖北省', map_name:'HB', map:'map_data/hubei.json'},
							{city:'武汉市', map_name:'WH', map:'map_data/wuhan.json'},
							{city:'荆州市', map_name:'JZ', map:'map_data/jingzhou.json'},
							{city:'恩施土家族苗族自治州', map_name:'ES', map:'map_data/enshi.json'},
							{city:'鄂州市', map_name:'EZ', map:'map_data/ezhou.json'},
							{city:'黄冈市', map_name:'HG', map:'map_data/huanggang.json'},
							{city:'黄石市', map_name:'HS', map:'map_data/huangshi.json'},
							{city:'荆门市', map_name:'JM', map:'map_data/jingmen.json'},
							{city:'十堰市', map_name:'SY', map:'map_data/shiyan.json'},
							{city:'随州市', map_name:'SZ', map:'map_data/suizhou.json'},
							{city:'襄阳市', map_name:'XY', map:'map_data/xiangyang.json'},
							{city:'咸宁市', map_name:'XN', map:'map_data/xianning.json'},
							{city:'孝感市', map_name:'XG', map:'map_data/xiaogan.json'},
							{city:'宜昌市', map_name:'YC', map:'map_data/yichang.json'},
							{city:'神农架林区', map_name:'SNJ', map:'map_data/shennongjia.json'},
							{city:'潜江市', map_name:'QJ', map:'map_data/qianjiang.json'},
							{city:'天门市', map_name:'TM', map:'map_data/tianmen.json'},
							{city:'仙桃市', map_name:'TM', map:'map_data/xiantao.json'},
						];

		// 地图加载数据，默认未加载任何数据
		var map_load = [];

		// 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('allmap'));

		// 当前地图数据
		var uploadedDataURL = "map_data/hubei.json";
		
		// 定义单击事件
		myChart.on('click', function (params) {
			console.log(params);
			load_map_data(params.name);
//			xqTable();
			var city = ["武汉市","十堰市","襄阳市","荆门市","孝感市","黄冈市","鄂州市","黄石市","咸宁市","荆州市","宜昌市","随州市","仙桃市","天门市","潜江市","神农架","恩施州"]
			$.each(city, function() {
				var n = 0;
				if(this == params.name){}else{n++;};
				if(n==city.length){
					
				}
			});
			
			function xqTable(){
				$(".modal").show();
				$(".tk").show();
			}
		});
		
		// 找到地图数据
		function get_map_data(name){
			console.log(name);
			for (i = 0; i < hubei_data.length; i++)
			{
				if (hubei_data[i].city == name)
				{
					return hubei_data[i];
				}
			}
		}

		// 加载地图数据
		function load_map_data(name)
		{
			var map = get_map_data(name);
			if (map == null){
				console.log('no map data');
			} else {
				uploadedDataURL = map.map;
				// data 为城市的数据
				data_arr = [
								{name: '武汉市', value: 20057.34}, 
//								{name: '荆州市', value: 15477.48}
						   ];
				load_chart(map, data_arr);
			}
		}
		

		function load_chart(map){
			// 最好写入过滤的方法，不要重复加载地图
			$.getJSON(uploadedDataURL, function (geoJson) {

				myChart.hideLoading();

				echarts.registerMap(map.map_name, geoJson);

				myChart.setOption(option = {
					title: {
						text: map.city + '数据',
						textStyle:{
							color:'#fff'
						}
//						subtext: '内保企业数据',
//						sublink: 'http://nb.yntosite.com'
					},
					tooltip: {
						trigger: 'item',
						formatter: '{c} '
					},
					toolbox: {
						show: false,
						orient: 'vertical',
						left: 'right',
						top: 'center',
						feature: {
							dataView: {readOnly: false},
							restore: {},
							saveAsImage: {}
						}
					},
					visualMap: {
						min: 800,
						max: 50000,
						text:['High','Low'],
						realtime: false,
						calculable: true,
//						color: ['orangered','yellow','lightskyblue']
						color: ['red','#4ad1ff','lightskyblue']
					},
					series: [
						{
							name: map.city,
							type: 'map',
							mapType: map.map_name, // 自定义扩展图表类型
							label:{
								normal:{
									textStyle:{color:"#fff"}//省份标签字体颜色
								}
							},
							itemStyle:{
								normal:{
									label:{show:true},
									borderColor: '#00bbec',//区域边框颜色
									areaColor:"transparent"//区域颜色
								},
								emphasis:{label:{show:true}}
							},
							data:data_arr
						}
					]
				});
			});
		}

		
		// 开始加载湖北地图
		load_map_data('湖北省');

		//load_hb();

 
	/*allmap_option = {
    "backgroundColor":'transparent',
    "tooltip": {
        "trigger": "item",
        "formatter":function(params,ticket,callback){

            var res= "<p>你好</p>";


         return res;
        },
    },
    "legend": {
        "orient": "vertical",
        "y": "80%",
        "x": "10%",
        "data": ["单位"],
        "itemWidth": 15,
        "itemHeight": 15,
        "textStyle": {
            "color": "#fff"
        }
    },
    "geo": {
       
        "map": "湖北",
        "layoutCenter": ["55%", "50%"],
        "layoutSize": "90%",
        "label": {
            "emphasis": {
                "show": true,
                textStyle:{
                   color:'#ccc',
                },
            }
        },
        "roam": true,
        "mapLocation": {
            "width": "95%",
            "height": "97%"
        },
        "itemStyle": {
            "normal": {
                shadowBlur: 20,
                shadowColor: 'rgba(0, 0, 0,0.8)',
                "areaColor": "#004571",
                "borderColor": "#6AC6E6"
            },
            "emphasis": {
                "areaColor": "#00385E"
            }
        }
    },
    "series": [{
        "name": "单位",
        "type": "effectScatter",
        "coordinateSystem": "geo",
        "data": [{
            "name": "武汉市",
            "value": [114.298572,30.584355]
        }, {
            "name": "荆州市",
            "value": [112.23813,30.326857]
        }, {
            "name": "宜昌市",
            "value": [111.290843,30.702636]
        }, {
            "name": "襄阳市",
            "value": [112.144146,32.042426]
        }, {
            "name": "十堰市",
            "value": [110.787916,32.646907]
        }, {
            "name": "荆门市",
            "value": [112.204251,31.03542]
        }, {
            "name": "孝感市",
            "value": [113.926655,30.926423]
        }],
        "rippleEffect": {
            "period": 4,
            "scale":4,
            "brushType": "stroke"
        },
        "label": {
            "normal": {
                "formatter": "{b}",
                "position": "left",
                "show": true,
            },
            "emphasis": {
                "show": true,
            }
        },
        "itemStyle": {
            "normal": {

                "color": "#FFD33D"
            }
        }
    },
   
    ]

};*/
  
  
  
  // 使用刚指定的配置项和数据显示图表。
//  allmap.setOption(allmap_option);	
  
  
 // 单位数量统计   
  
 var shul = echarts.init(document.getElementById('shul'));
 
 shul_option = {
    backgroundColor: 'transparent',

    title: {
//      text: 'Customized Pie',
        left: 'center',
        top: 20,
        textStyle: {
            color: '#ccc'
        }
    },

    tooltip : {
        trigger: 'item',
        formatter: "{a} <br/>{b} : {c} ({d}%)"
    },

    visualMap: {
        show: false,
        min: 80,
        max: 600,
        inRange: {
            colorLightness: [0, 1]
        }
    },
    series : [
        {
            name:'单位数量',
            type:'pie',
            radius : '55%',
            center: ['50%', '50%'],
            data:[
                {value:335, name:'武汉市'},
                {value:310, name:'荆州市'},
                {value:244, name:'黄石市'},
                {value:288, name:'宜昌市'},
                {value:320, name:'襄阳市'},
                {value:310, name:'十堰市'},
                {value:266, name:'荆门市'},
                {value:120, name:'鄂州市'},
                {value:352, name:'孝感市'},
                {value:155, name:'咸宁市'},
                {value:110, name:'随州市'},
                {value:340, name:'恩施州'},
                {value:150, name:'黄冈市'},
            
               
            ].sort(function (a, b) { return a.value - b.value; }),
            roseType: 'radius',
            label: {
                normal: {
                    textStyle: {
                        color: 'rgba(255, 255, 255, 0.3)'
                    }
                }
            },
            labelLine: {
                normal: {
                    lineStyle: {
                        color: 'rgba(255, 255, 255, 0.3)'
                    },
                    smooth: 0.2,
                    length: 10,
                    length2: 20
                }
            },
            itemStyle: {
                normal: {
                    color: '#c23531',
                    shadowBlur: 200,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
            },

            animationType: 'scale',
            animationEasing: 'elasticOut',
            animationDelay: function (idx) {
                return Math.random() * 200;
            }
        }
    ]
};
 
// 使用刚指定的配置项和数据显示图表。
        shul.setOption(shul_option);	 
   
// 单位级别数量统计          
var jbshul = echarts.init(document.getElementById('jbshul'));
 
jbshul_option = {
    color: ['#3398DB'],
    tooltip : {
        trigger: 'axis',
        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
        }
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
    xAxis : [
        {
            type : 'category',
            data : ['非重点', '省级', '市级', '县级', '乡级'],
            axisTick: {
                alignWithLabel: true
            },
             axisLabel: {
                            show: true,
                            textStyle: {
                                color: '#fff'
                            }
                        }
        }
    ],
    yAxis : [
        {
            type : 'value',
            axisLabel: {
                            show: true,
                            textStyle: {
                                color: '#fff'
                            }
                        }
        }
    ],
    series : [
        {
            name:'数量',
            type:'bar',
            barWidth: '60%',
            data:[10, 32, 20, 34, 39]
        }
    ]
};

// 使用刚指定的配置项和数据显示图表。
        jbshul.setOption(jbshul_option);	 
        
// 单位性质数量统计       
var xzshul = echarts.init(document.getElementById('xzshul'));
xzshul_option = {
   
    tooltip: {},
    legend: {
       
    },
    radar: {
        // shape: 'circle',
        indicator: [
           { name: '国有企业'},
           { name: '民营'},
           { name: '事业单位'}
        ]
    },
    series: [{
        name: '单位性质数量统计',
        type: 'radar',
        // areaStyle: {normal: {}},
        data : [
            {
                value : [30, 20, 35],
                name : '武汉市'
            }
        ]
    }]
};
// 使用刚指定的配置项和数据显示图表。
        xzshul.setOption(xzshul_option);
        
//保卫人员数量统计
var bwshul = echarts.init(document.getElementById('bwshul'));

bwshul_option = {
   
    tooltip : {
        trigger: 'axis',
        axisPointer: {
            type: 'cross',
            label: {
                backgroundColor: 'transparent'
            }
        }
    },
    legend: {
        data:['保卫人员数量'],
        textStyle:{    //图例文字的样式
	        color:'#fff',
	    }
    },
    toolbox: {
    	show:false,
        feature: {
            saveAsImage: {}
        }
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
    xAxis : [
        {
            type : 'value',
            boundaryGap : false,
             axisLabel: {
                            show: true,
                            textStyle: {
                                color: '#fff'
                            }
                        }
        }
    ],
    yAxis : [
        {
            type : 'category',
            data : ['武汉市','荆州市','宜昌市','黄石市','孝感市','十堰市','荆门市','恩施州','天门市','神农架','鄂州市','襄阳市','咸宁市'],
             axisLabel: {
                            show: true,
                            textStyle: {
                                color: '#fff'
                            }
                        }
        }
    ],
    series : [
        {
            name:'保卫人员数量',
            type:'line',
            stack: '总量',
            areaStyle: {normal: {}},
            data:[120, 132, 101, 134, 90, 230, 210,150,650,120,440,220,330]
        },
       
      
       
    ]
};


// 使用刚指定的配置项和数据显示图表。
        bwshul.setOption(bwshul_option);
        
//重点部位数量统计
var zdbwshul = echarts.init(document.getElementById('zdbwshul'));
zdbwshul_option = {
    color: ['#3398DB'],
    tooltip : {
        trigger: 'axis',
        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
        }
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
    xAxis : [
        {
            type : 'category',
            data : ['武汉市', '荆门市', '黄冈市', '宜昌市', '襄阳市', '天门市', '南山市'],
            axisTick: {
                alignWithLabel: true
            },
              axisLabel: {
                            show: true,
                            textStyle: {
                                color: '#fff'
                            }
                        }
        }
    ],
    yAxis : [
        {
            type : 'value',
	          axisLabel: {
	                        show: true,
	                        textStyle: {
	                            color: '#fff'
	                        }
	                   },
        }
    ],
    series : [
        {
            name:'重点部位数量',
            type:'bar',
            barWidth: '60%',
            data:[60, 52, 70, 80, 66, 77, 55],
             itemStyle:{
                        normal:{
                            color:'#e84022'
                        }
                    }
        }
    ]
};

// 使用刚指定的配置项和数据显示图表。
        zdbwshul.setOption(zdbwshul_option);
        
//重点维稳人员数量统计
var zdwwshul = echarts.init(document.getElementById('zdwwshul'));
zdwwshul_option = {
    color: ['#3398DB'],
    tooltip : {
        trigger: 'axis',
        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
        }
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
    xAxis : [
        {
            type : 'category',
            data : ['武汉市', '荆门市', '黄冈市', '宜昌市', '襄阳市', '天门市', '南山市'],
            axisTick: {
                alignWithLabel: true
            },
              axisLabel: {
                            show: true,
                            textStyle: {
                                color: '#fff'
                            }
                        }
        }
    ],
    yAxis : [
        {
            type : 'value',
	          axisLabel: {
	                        show: true,
	                        textStyle: {
	                            color: '#fff'
	                        }
	                   },
        }
    ],
    series : [
        {
            name:'重点维稳人员数量',
            type:'bar',
            barWidth: '60%',
            data:[60, 52, 70, 80, 66, 77, 55],
             itemStyle:{
                        normal:{
                            color:'#4cebf7'
                        }
                    }
        }
    ]
};
// 使用刚指定的配置项和数据显示图表。
        zdwwshul.setOption(zdwwshul_option);
        

//单位状态数量统计
var zdztshul = echarts.init(document.getElementById('zdztshul'));
zdztshul_option = {
    tooltip : {
        trigger: 'item',
        formatter: "{a} <br/>{b} : {c} ({d}%)"
    },
    legend: {
        orient: 'vertical',
        left: 'left',
        data: ['实有','变更','注销'],
        textStyle:{    //图例文字的样式
        	color:'#fff',
    }
    },
    series : [
        {
            name: '访问来源',
            type: 'pie',
            radius : '55%',
            center: ['50%', '60%'],
            data:[
                {value:335, name:'实有'},
                {value:310, name:'变更'},
                {value:234, name:'注销'},
               
            ],
            itemStyle: {
                emphasis: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
            }
        }
    ]
};

// 使用刚指定的配置项和数据显示图表。
        zdztshul.setOption(zdztshul_option);
        
//行业类别数量统计
var hylbul = echarts.init(document.getElementById('hylbul'));
hylbul_option = {
    tooltip : {
        trigger: 'item',
        formatter: "{a} <br/>{b} : {c} ({d}%)"
    },
    legend: {
        orient: 'vertical',
        left: 'left',
        data: ['党政机关','卫生系统','高校','中小学幼儿园','商场超市','银行/金融机构','加油(气)站','其他单位'],
        textStyle:{    //图例文字的样式
        	color:'#fff'
    }
    },
    series : [
        {
            name: '行业类别数量',
            type: 'pie',
            radius : '55%',
            center: ['50%', '60%'],
            data:[
                {value:15, name:'党政机关'},
                {value:9, name:'卫生系统'},
                {value:20, name:'高校'},
                {value:30, name:'中小学幼儿园'},
                {value:40, name:'商场超市'},
                {value:32, name:'银行/金融机构'},
                {value:40, name:'加油(气)站'},
                {value:60, name:'其他单位'},
            ],
            itemStyle: {
                emphasis: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
            }
        }
    ]
};
// 使用刚指定的配置项和数据显示图表。
        hylbul.setOption(hylbul_option);
        
//汇总统计
var huizong = echarts.init(document.getElementById('huizong'));
huizong_option = {
    color: ['#3398DB'],
    tooltip : {
        trigger: 'axis',
        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
        }
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
    xAxis : [
        {
            type : 'category',
            data : ['单位数量', '单位', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
            axisTick: {
                alignWithLabel: true
            }
        }
    ],
    yAxis : [
        {
            type : 'value'
        }
    ],
    series : [
        {
            name:'直接访问',
            type:'bar',
            barWidth: '60%',
            data:[10, 52, 200, 334, 390, 330, 220]
        }
    ]
};
